package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
@Controller
public class Login {
    @Autowired
    private UserService userService;

    //登录
    @RequestMapping("login")
    public String login(User user, HttpSession session){
        //通过账户名跟密码获取user对象
        User user1=userService.findByNameAndPwd(user.getUserName(),user.getPassword());
        //user有数据说明查询到了
        if(user1!=null){
            //添加到session域中，方便拦截
            session.setAttribute("user",user1);
            return "redirect:/user/findAll";
        }else{
            return "login";
        }
    }
}
